package stat;

import tsd.TSD;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * Author: Oleg Yasnev (oyasnev@gmail.com)
 * Date: 24.05.14
 */
public class TSDLengthChart extends TSDStatChart {

    public TSDLengthChart(int locX, int locY) {
        super(locX, locY);
        chartHeader = "TSD length distribution";
        chartTitle  = "TSD length distribution";
        xTitle      = "TSD length";
        yTitle      = "Count";
        seriesName  = "TSD length";
    }

    @Override
    protected void updateData(List<TSD> tsdList) {
        Map<Integer, Integer> map = new TreeMap<Integer, Integer>();
        for (TSD tsd : tsdList) {
            if (tsd.hasTSD) {
                int len = tsd.length();
                int count = map.containsKey(len) ? map.get(len) : 0;
                map.put(len, count + 1);
            }
        }
        xData.clear();
        yData.clear();
        for (Integer x : map.keySet()) {
            xData.add(x * 1.0);
            yData.add(map.get(x) * 1.0);
        }
    }
}
